home *** CD-ROM | disk | FTP | other *** search
- // Graphics Importer and Exporter Samples
- // This sample simply draws an image from a file using Graphics Importers
- // Originally written by Sam Bushell for QuickTime "Live" '99
- // WWDC 2000 Introduction to QuickTime
-
- #include "MacShell.h"
-
- void DrawImage( void )
- {
- OSErr err = noErr;
- Handle hOpenTypeList = NewHandle(0);
- long numTypes = 0;
- FSSpec theFSSpec;
- Rect bounds;
- GraphicsImportComponent importer = 0;
- WindowPtr window = NULL;
-
- BuildGraphicsImporterValidFileTypes( hOpenTypeList, &numTypes );
- HLock( hOpenTypeList );
-
- err = GetOneFileWithPreview(numTypes, (OSTypePtr)*hOpenTypeList, &theFSSpec, NULL);
- DisposeHandle( hOpenTypeList );
- if ( err ) return;
-
- // locate and open a graphics importer component which can be used to draw the
- // selected file. If a suitable importer is not found the ComponentInstance
- // is set to NULL.
- err = GetGraphicsImporterForFile( &theFSSpec, // specifies the file to be drawn
- &importer ); // pointer to the returned GraphicsImporterComponent
-
- // get the native size of the image associated with the importer
- err = GraphicsImportGetNaturalBounds( importer, // importer instance
- &bounds ); // returned bounds
-
- OffsetRect( &bounds, 10, 45 );
- window = NewCWindow( NULL, &bounds, "\pDraw Image", true, documentProc, (WindowPtr)-1, true, 0);
-
- // set the graphics port for drawing
- err = GraphicsImportSetGWorld( importer, // importer instance
- GetWindowPort( window ), // destination graphics port or GWorld
- NULL ); // destination GDevice, set to NULL uses GWorlds device
-
- // draw the image
- err = GraphicsImportDraw( importer );
-
- // close the importer instance
- CloseComponent( importer );
- }
-